import {DefaultOptionType} from "rc-select/lib/Select";
import {Badge, Space} from "antd";
import {requestClientList, requestEngineInfo, requestPartGroupList, requestPartProviderList} from "./RequestHandler";

/**
 * 获取发动机Select表单的选项
 */
export const getEngineOptions = async (): Promise<DefaultOptionType[]> => {
    let engineRes = await requestEngineInfo() ;
    if (engineRes.success){
        return engineRes.data.map(engine => {
            return {key: engine.key, value: engine.id, label: engine.engineSerial + " == " + engine.engineModel} ;
        }) ;
    }
    return [] ;
} ;
/**
 * 获取供应商Select表单的选项
 */
export const getProviderOptions = async (): Promise<DefaultOptionType[]> => {
    let providerRes = await requestPartProviderList() ;
    if (providerRes.success){
        return providerRes.data.map(provider => {
            return {key: provider.key, value: provider.id, label: provider.providerName} ;
        }) ;
    }
    return [] ;
} ;
/**
 * 获取零件分组Select表单的选项
 */
export const getPartGroupOptions = async (): Promise<DefaultOptionType[]> => {
    let partGroupRes = await requestPartGroupList();
    if (partGroupRes.success){
        return partGroupRes.data.map(group => {
            return {key: group.key, value: group.id, label: group.groupName} ;
        }) ;
    }
    return [] ;
} ;
/**
 * 获取客户Select表单的选项
 */
export const getClientOptions = async (): Promise<DefaultOptionType[]> => {
    const clintRes = await requestClientList() ;
    if (clintRes.success){
        return clintRes.data.map(client => {
            let tempNode = <Space><Badge status={ client.clientType === "person" ? "success" : "processing" } /> { client.clientName + (client.clientPrincipal ? " [ " + client.clientPrincipal + " ] " : "") } </Space> ;
            return {key: client.key, value: client.id, label: tempNode} ;
        }) ;
    }
    return [] ;
} ;

